﻿//逻辑层

//文件拖拽
function init() {
    //教用文件拖拽
    var jiaoshikuang = document.getElementById("jiaoshiC");
    jiaoshikuang.addEventListener("dragover", function (ev) {
        ev.stopPropagation();
        ev.preventDefault();
    }, false);
    jiaoshikuang.addEventListener("dragend", function (ev) {
        ev.stopPropagation();
        ev.preventDefault();
    }, false);
    jiaoshikuang.addEventListener("drop", function (ev) {
        ev.stopPropagation();
        ev.preventDefault();
        var file = ev.dataTransfer.files[0];
        var reader = new FileReader();
        var fileName = file.name;
        if (fileName.substr(-3, 3) == "fbd") {
            reader.readAsText(file, "gb2312");
            reader.onload = function (f) {
                jiaoshiTxt = this.result;
                jiaoshiTxt = jiaoshiTxt.replace(/&/g, "&amp;");
                jiaoshiTxt = jiaoshiTxt.replace(/</g, "&lt;");
                jiaoshiTxt = jiaoshiTxt.replace(/>/g, "&gt;");
                jiaoshiTxt = jiaoshiTxt.replace(/"/g, "&quot;");
                jiaoshiTxt = jiaoshiTxt.replace(/'/g, "&apos;");
                document.getElementById("jiaoshiC").innerHTML = jiaoshiTxt;
                document.getElementById("jiaoshiwenjianming-box").innerHTML = "";
                var spanObj = document.createElement('span');
                spanObj.innerHTML = fileName;
                spanObj.setAttribute("id", "jiaoshiwenjianming");
                document.getElementById("jiaoshiwenjianming-box").appendChild(spanObj);
                $(function () {
                    $("#xueshengC").html("");
                    $("#xueshengzifu").html(0);
                    $("#xueshengbiaoti").html("答案部分");
                    $("#xueshengbiaoti").css("color", colorMoshi4);
                    $("#daanC").html("");
                    $("#daanzifu").html(0);
                    $("#daanbiaoti").html("答案部分");
                    $("#daanbiaoti").css("color", colorMoshi4);
                    jiaoshishuru();
                })
            }
        }
    }, false);
}
//设置页面属性，不执行默认处理（拒绝被拖放）
document.ondragover = function (e) { e.preventDefault(); };
document.ondrop = function (e) { e.preventDefault(); }
window.onload = init;

//主题设置
var colorMoshi1 = "royalblue";
var colorMoshi2 = "white";
var colorMoshi3 = "black";
var colorMoshi4 = "#c2c2c2";
var colorMoshi5 = "#c3e9c9"
var colorMoshi6 = "orange";
var colorMoshi7 = "#FF00FF";
var colorMoshi8 = "#cec7fa";
var colorMoshi10 = "red";

//数据设置
infoJson = [
    // ["不限", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|测试卷|检测卷).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|测试卷|检测卷)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)"],
    // ["不限", "图书类", "教用 分 学用 / 固用（英语）", "((〖.+?名言潮语.+?〗)|(〖=BT[(（]〗Section.+?〖=〗))[\\s\\S]+?(.+?课后精练.+)", "((.+?课后精练.+)[\\s\\S]+?(〖=BT[(（]〗Section.+?〖=〗))|((.+?课后精练.+)[\\s\\S]+?(〖.+?名言潮语.+?〗))|((.+?课后精练.+)[\\s\\S]+?$)"],
    // ["不限", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{4,6}[^\\u4e00-\\u9fa5]+)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],

    //语文
    ["语文", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|综合训练|单元训练|测试卷|检测卷).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|综合训练|单元训练|测试卷|检测卷)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19)[\\s\\S]+?〖MZ[）)]〗)|(〖MZ[（(]1\\+H〗[\\s\\S]+?〖MZ[）)]〗)"],
    ["语文", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{4,6}[^\\u4e00-\\u9fa5]+?〗.*)|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(〖=BT[（(]〗〖HTXBS〗.+?〖=〗)|(.*?〖HT(20|18|19)[\\s\\S]+?〖MZ[）)]〗)|(〖ZDLYL[（(]〗〖.+?练一练.+?〗)|(〖HS[（(]*.*?〗〖.+?〗任务[一二三四五六七八九十])|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)|(〖MZ[（(]1\\+H〗[\\s\\S]+?〖MZ[）)]〗)"],
    ["语文", "图书类", "删 教师讲解", "〖=DBSF[（(]〗(〖HT(SS)*〗)*[（(]教师讲解内容：〖=〗[\\s\\S]+?〖=DBSF[（(]〗[）)]*〖=〗*(〖HT(SS)*〗)**", "〖=DBSF[（(]〗(〖HT(SS)*〗)*[（(]教师讲解内容：〖=〗[\\s\\S]+?〖=DBSF[（(]〗[）)]*〖=〗*(〖HT(SS)*〗)**"],
    ["语文", "图书类", "删 主观题答案", "(?<=\\n)[（(][^(（）)]+?[）)](?=.*?〖ZK[）)]〗)", "(?<=\\n)[（(][^(（）)]+?[）)](?=.*?〖ZK[）)]〗)"],
    //数学
    ["数学", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|测试卷|检测卷).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|测试卷|检测卷)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19)[\\s\\S]+?[])"],
    ["数学", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{1,6}[^\\u4e00-\\u9fa5]+?〗.*)|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|((?<=\\n)\\d+[.．])|((?<=\\n)[（(]\\d+[)）])|(〖=[2A][（(]〗[\\s\\S]+?〖=〗)|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],
    //英语
    ["英语", "图书类", "教用 分 学用 / 固用", "((〖.+?名言潮语.+?〗)|(〖=BT[(（]〗Section[\\s\\S]+?〖=〗))[\\s\\S]+?(.+?课后精练.+)", "(〖=BT[(（]〗.+?〖=〗[]*)|((.+?课后精练.+)[\\s\\S]+?(〖=BT[(（]〗Section[\\s\\S]+?〖=〗))|((.+?课后精练.+)[\\s\\S]+?(〖.+?名言潮语.+?〗))|((.+?课后精练.+)[\\s\\S]+?$)"],
    ["英语", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{3,4}[^\\u4e00-\\u9fa5]+?〗.*)|((?<=\\n)\\d+[.．])|((?<=\\n)[（(]\\d+[)）])|(〖XC24Step.+?〗[]*)|(〖HTH〗[ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ].+?〖HT(SS)*〗[]*)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(〖=(BT|HD)\\d*[(（]〗[\\s\\S]+?〖=〗[]*)|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],
    //政治
    ["政治", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|单元检测).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|单元检测)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)|(〖MZ[（(]1\\+H〗[\\s\\S]+?〖MZ[）)]〗)"],
    ["政治", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{3,6}[^\\u4e00-\\u9fa5]+?〗.*)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|〖HS3〗〖JZ〗〖HZ[(（]〗〖HT14[.．]《方正粗雅宋简体》〗议题.+[]|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)|(〖MZ[（(]1\\+H〗[\\s\\S]+?〖MZ[）)]〗)"],
    //历史
    ["历史", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|测试卷|检测卷|单 元 总 结).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|测试卷|检测卷|单 元 总 结)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)"],
    ["历史", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{4,6}[^\\u4e00-\\u9fa5]+?〗.*)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(〖HT5H〗【探究与拓展】〖HT〗[]*)|(〖HT《方正.+?》〗[\\u4e00-\\u9fa5]{3,4}.*?〖HT〗)|(〖HT14.*?〗任务〖KG.*?〗〖ST.*?〗\\d+〖ST〗〖HT14.*?〗)|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],
    //地理
    ["地理", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|测试卷|检测卷).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|测试卷|检测卷)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)"],
    ["地理", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{3,6}[^\\u4e00-\\u9fa5]+?〗.*)|(〖HS[（(]2〗.*?〖XC\\d*活动[^\\u4e00-\\u9fa5]+?〗[\\s\\S]*?〖HS[)）]〗)|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|((?<=(〖=(QJ|2)[（(]〗)).+?(?=(〖=〗)))|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],
    //物理
    ["物理", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|专题强化|单元检测).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|专题强化|单元检测)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)|(〖MZ[（(]1\\+H〗[\\s\\S]+?〖MZ[）)]〗)"],
    ["物理", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{4,6}[^\\u4e00-\\u9fa5]+?〗.*)|(〖XC24例.+?〗.+?〖HT〗)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(任务\\d*〓〖HT.+?《方正.+?》〗)|(〖HT.+?《方正.+?》〗.+?活动\\d*.+?〖HT〗)|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|((?<=\\n)\\d+[.．])|((?<=\\n)[（(]\\d+[)）])|((?<=〖HTH〗)思考\\d*(?=[：:]))|(〖MZ[（(]1\\+H〗[\\s\\S]+?〖MZ[）)]〗)|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],
    ["物理", "图书类", "删 教师讲解", "*\\n*〖HTH〗【解析】〖HTSS〗[\\s\\S]+?(?=〖ZK[)）]〗)", "*\\n*〖HTH〗【解析】〖HTSS〗[\\s\\S]+?(?=〖ZK[)）]〗)"],
    //化学
    ["化学", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|测试卷|检测卷).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|测试卷|检测卷)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)"],
    ["化学", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{4}[^\\u4e00-\\u9fa5]+?〗.*)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(【.*?例\\d+】)|(〖=RW[（(]〗.+?〖=〗)|((?<=\\n)\\d+[.．])|((?<=\\n)[（(]\\d+[)）])|((?<=\\n〖HT.+?H〗〖ST.+?FZ〗)\\d+[.．])|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],
    //生物
    ["生物", "图书类", "教用 分 学用 / 固用", "(?<=(.+(课后精练|综合测试|单元训练|测试卷|检测卷).+[]))[\\s\\S]+?〖FL[)）]0*?〗", "(.+(课后精练|综合测试|单元训练|测试卷|检测卷)[\\s\\S]+?〖FL[)）]0*?〗)|(.*?〖HT(20|18|19).+)|(〖PS第[一二三四五六七八九十]章.+?〗)|(〖=BT\\d+[（(]〗第\\d+(节|课时).+?〖=〗[])"],
    ["生物", "图书类", "学用 / 固用 分 答案", "〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗", "(.*?〖XC\\d*[\\u4e00-\\u9fa5]{1,6}[^\\u4e00-\\u9fa5]+?〗.*)|(.*?〖HT(20|18|19)[\\s\\S]+?[])|(〖=(1|A|D|B|XH)[（(]〗\\d+[.．]〖=〗)|(〖=(A|BT3|RW\\d*|HD[AB]|HD|E)[（(]〗[\\s\\S]+?〖=〗)|((?<=\\n)\\d+[.．])|((?<=\\n)[（(]\\d+[)）])|(〖PS第[一二三四五六七八九十]章.+?〗[]*)|(〖=BT\\d+[（(]〗第\\d+(节|课时).+?〖=〗[]*)|(〖QX[（(]Z0〗[\\s\\S]+?〖QX[)）]〗)"],

]

//启动事件
function start() {
    $(".copydaan-box").hide();
    shuju();
    cp2 = $("#chanpin2").val();
    chanpin2Panding();
    $("#chanpin2").val(cp2);
    tiqu1Panding();
    tiqu1quedingY();
    tiqu2Panding();
    tiqu2quedingY();
    daangeshikemupanding();
    xueshenggeshikemupanding();
    chaifenPanding();
    chaifenfuwei();
    // $("#jiaoshiC").html(localStorage.getItem("jiaoshiC-BET"));
    $("#leibie").val(localStorage.getItem("leibie-BET"));
    leibiexiala();
    $("#chanpin1").val(localStorage.getItem("chanpin1-BET"));
    chanpin1xiala();
    $("#chanpin2").val(localStorage.getItem("chanpin2-BET"));
    chanpin2xiala();
    swal("书版11.0导入提醒", "请使用下方 “书版按钮” 导入或直接 “拖拽fbd文件” 导入，\n请勿直接复制进来，否则特殊符号会失效", "info");
}

//数据加载
function shuju() {
    $("#leibie").html("");
    $("#chanpin1").html("");
    var kemu = [];
    var leixing = [];
    for (i = 0; i < infoJson.length; i++) {
        if (kemu.indexOf(infoJson[i][0]) == -1) {
            kemu.push(infoJson[i][0]);
        }
        if (leixing.indexOf(infoJson[i][1]) == -1) {
            leixing.push(infoJson[i][1]);
        }
    }
    for (i = 0; i < kemu.length; i++) {
        $("#leibie").append('\
            <option value="' + kemu[i] + '">' + kemu[i] + '</option>\
        ');
    }
    for (i = 0; i < leixing.length; i++) {
        $("#chanpin1").append('\
            <option value="' + leixing[i] + '">' + leixing[i] + '</option>\
        ');
    }
}

//类别下拉
function leibiexiala() {
    cp2 = $("#chanpin2").val();
    chanpin2Panding();
    $("#chanpin2").val(cp2);
    tiqu1Panding();
    tiqu1quedingY();
    tiqu2Panding();
    tiqu2quedingN();
    daangeshikemupanding();
    xueshenggeshikemupanding();
    chaifenPanding();
    chaifenfuwei();
}

//产品一类下拉
function chanpin1xiala() {
    cp2 = $("#chanpin2").val();
    chanpin2Panding();
    $("#chanpin2").val(cp2);
    tiqu1Panding();
    tiqu1quedingY();
    tiqu2Panding();
    tiqu2quedingN();
    daangeshikemupanding();
    xueshenggeshikemupanding();
    chaifenPanding();
    chaifenfuwei();
}

//产品二类判定
function chanpin2Panding() {
    $("#chanpin2").html("");
    for (i = 0; i < infoJson.length; i++) {
        if ($("#leibie").val() == infoJson[i][0] && $("#chanpin1").val() == infoJson[i][1]) {
            $("#chanpin2").append("<option value='" + infoJson[i][2] + "'>" + infoJson[i][2] + "</option>");
        }
    }
}

//产品二类下拉
function chanpin2xiala() {
    tiqu1Panding();
    tiqu1quedingY();
    tiqu2Panding();
    tiqu2quedingN();
    daangeshikemupanding();
    xueshenggeshikemupanding();
    chaifenPanding();
    chaifenfuwei();
}

//学生下拉
function xueshengxiala() {
    xueshengXialaZhengzePanding();
    tiqu1quedingN();
    chaifenPanding();
    chaifenfuwei();
}

//学生正则判定
function xueshengXialaZhengzePanding() {
    if ($("#xuesheng").val() == "学生") {
        tiqu1Panding();
    }
}

//提取1判定
function tiqu1Panding() {
    for (i = 0; i < infoJson.length; i++) {
        if ($("#leibie").val() == infoJson[i][0] && $("#chanpin1").val() == infoJson[i][1] && $("#chanpin2").val() == infoJson[i][2]) {
            $("#tiqu1").val(infoJson[i][3]);
            return;
        }
    }
}

//提取1输入
function tiqu1shuru() {
    jiaoshigaoliangN();
    var jiaoshiC = $("#jiaoshiC").html();
    var tiqu1 = $("#tiqu1").val();
    tiqu1shuruZhengzePanding();
    if (jiaoshiC != "" && tiqu1 != "") {
        tiqu1quedingN();
    } else {
        $("#tiqu1queding").removeClass("div-box-top-xianshi-queding").addClass("div-box-top-xianshi-queding-jinzhi");
    }
    chaifenPanding();
    chaifenfuwei();
}

//提取1输入正则判定
function tiqu1shuruZhengzePanding() {
    $("#xuesheng").val("自定义");
    for (i = 0; i < infoJson.length; i++) {
        if ($("#leibie").val() == infoJson[i][0] && $("#chanpin1").val() == infoJson[i][1] && $("#chanpin1").val() == infoJson[i][1] && $("#tiqu1").val() == infoJson[i][3]) {
            $("#xuesheng").val("学生");
            return;
        }
    }
}

//提取1按钮
function tiqu1queding() {
    tiqu1quedingY();
    chaifenPanding();
}

//提取1按钮开启
function tiqu1quedingY() {
    var chanpin2 = $("#chanpin2").val();
    if ($("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding") {
        jiaoshigaoliangN();
        $("#tiqu1queding").removeClass("div-box-top-xianshi-queding").addClass("div-box-top-xianshi-queding-jinzhi");
        var jiaoshiC = $("#jiaoshiC").html();
        if (jiaoshiC != "" && jiaoshiC != "<br>") {
            var tiqu1 = $("#tiqu1").val();
            if (tiqu1 != "") {
                jiaoshiC = jiaoshiC.replace(/(?<!\\)\[/g, "〖");
                jiaoshiC = jiaoshiC.replace(/(?<!\\)\]/g, "〗");
                var jiaoshiCount = jiaoshiC.match(new RegExp(tiqu1, 'g'));
            } else {
                var jiaoshiCount = null;
            }
            if (jiaoshiCount != null) {
                if (chanpin2.indexOf("分 学用") >= 0) {
                    $("#jiaoshibiaoti").html("教用部分 学用 " + jiaoshiCount.length);
                } else if (chanpin2.indexOf("分 答案") >= 0) {
                    $("#jiaoshibiaoti").html("学用/固用部分 学生/固学案 " + jiaoshiCount.length);
                } else {
                    $("#jiaoshibiaoti").html("教用部分 学用 " + jiaoshiCount.length);
                }
            } else {
                if (chanpin2.indexOf("分 学用") >= 0) {
                    $("#jiaoshibiaoti").html("教用部分 学用 0");
                } else if (chanpin2.indexOf("分 答案") >= 0) {
                    $("#jiaoshibiaoti").html("学用/固用部分 学生/固学案  0");
                } else {
                    $("#jiaoshibiaoti").html("教用部分 学用 0");
                }
            }
        } else {
            $("#jiaoshibiaoti").html("教用部分");
        }
        if ($("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu2 != "") {
            $("#tiqu2queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
        }
    }
}

//提取1按钮关闭
function tiqu1quedingN() {
    var jiaoshiC = $("#jiaoshiC").html();
    var tiqu1 = $("#tiqu1").val();
    if ($("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu1 != "") {
        $("#tiqu1queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
    }
    $("#jiaoshibiaoti").html("教用部分");
    chaifenfuwei();
}

//答案下拉
function daanxiala() {
    daanXialaZhengzePanding();
    tiqu2quedingN();
    chaifenPanding();
    chaifenfuwei();
}

//答案正则判定
function daanXialaZhengzePanding() {
    if ($("#daan").val() == "答案") {
        tiqu2Panding();
    }
}

//提取2判定
function tiqu2Panding() {
    for (i = 0; i < infoJson.length; i++) {
        if ($("#leibie").val() == infoJson[i][0] && $("#chanpin1").val() == infoJson[i][1] && $("#chanpin2").val() == infoJson[i][2]) {
            $("#tiqu2").val(infoJson[i][4]);
            return;
        }
    }
}

//提取2输入
function tiqu2shuru() {
    jiaoshigaoliangN();
    var jiaoshiC = $("#jiaoshiC").html();
    var tiqu2 = $("#tiqu2").val();
    tiqu2shuruZhengzePanding();
    if (jiaoshiC != "" && tiqu2 != "") {
        tiqu2quedingN();
    } else {
        $("#tiqu2queding").removeClass("div-box-top-xianshi-queding").addClass("div-box-top-xianshi-queding-jinzhi");
    }
    chaifenPanding();
    chaifenfuwei();
}

//提取2输入正则判定
function tiqu2shuruZhengzePanding() {
    $("#daan").val("自定义");
    for (i = 0; i < infoJson.length; i++) {
        if ($("#leibie").val() == infoJson[i][0] && $("#chanpin1").val() == infoJson[i][1] && $("#chanpin2").val() == infoJson[i][2] && $("#tiqu2").val() == infoJson[i][4]) {
            $("#daan").val("答案");
            return;
        }
    }
}

//提取2按钮
function tiqu2queding() {
    tiqu2quedingY();
    chaifenPanding();
}

//提取2按钮开启
function tiqu2quedingY() {
    var chanpin2 = $("#chanpin2").val();
    if ($("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding") {
        jiaoshigaoliangN();
        $("#tiqu2queding").removeClass("div-box-top-xianshi-queding").addClass("div-box-top-xianshi-queding-jinzhi");
        var jiaoshiC = $("#jiaoshiC").html();
        if (jiaoshiC != "" && jiaoshiC != "<br>") {
            var tiqu2 = $("#tiqu2").val();
            if (tiqu2 != "") {
                jiaoshiC = jiaoshiC.replace(/\[/g, "〖");
                jiaoshiC = jiaoshiC.replace(/\]/g, "〗");
                var jiaoshiCount = jiaoshiC.match(new RegExp(tiqu2, 'g'));
            } else {
                var jiaoshiCount = null;
            }
            if (jiaoshiCount != null) {
                if (chanpin2.indexOf("分 学用") >= 0) {
                    $("#jiaoshibiaoti").html("教用部分 固用 " + jiaoshiCount.length);
                } else if (chanpin2.indexOf("分 答案") >= 0) {
                    $("#jiaoshibiaoti").html("学用/固用部分 答案 " + jiaoshiCount.length);
                } else {
                    $("#jiaoshibiaoti").html("教用部分 答案 " + jiaoshiCount.length);
                }
            } else {
                if (chanpin2.indexOf("分 学用") >= 0) {
                    $("#jiaoshibiaoti").html("教用部分 固用 0");
                } else if (chanpin2.indexOf("分 答案") >= 0) {
                    $("#jiaoshibiaoti").html("学用/固用部分 答案 0");
                } else {
                    $("#jiaoshibiaoti").html("教用部分 答案 0");
                }
            }
        } else {
            $("#jiaoshibiaoti").html("教用部分");
        }
        if ($("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu2 != "") {
            $("#tiqu1queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
        }
    }
}

//提取2按钮关闭
function tiqu2quedingN() {
    var jiaoshiC = $("#jiaoshiC").html();
    var tiqu2 = $("#tiqu2").val();
    if ($("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu2 != "") {
        $("#tiqu2queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
    }
    $("#jiaoshibiaoti").html("教用部分");
    chaifenfuwei();
}

//学生格式
function xueshengsz() {
    if ($("#xueshengsz").attr("class") == "div-box-top-xianshi-fuxuan") {
        $("#xueshengsz").removeClass("div-box-top-xianshi-fuxuan").addClass("div-box-top-xianshi-fuxuan-xuanze");
        $("#daansz").removeClass("div-box-top-xianshi-fuxuan-xuanze").addClass("div-box-top-xianshi-fuxuan");
        $("#xueshenggeshishezhi").fadeIn("slow");
        $(".div-box-center-in").scrollLeft(3000);
        $("#daangeshishezhi").hide();
    } else if ($("#xueshengsz").attr("class") == "div-box-top-xianshi-fuxuan-xuanze") {
        $("#xueshengsz").removeClass("div-box-top-xianshi-fuxuan-xuanze").addClass("div-box-top-xianshi-fuxuan");
        $(".div-box-center-in").scrollLeft(0);
    }
}

//学生格式科目判定
function xueshenggeshikemupanding() {
    var leibie = $("#leibie").val();
    var chanpin1 = $("#chanpin1").val();
    var chanpin2 = $("#chanpin2").val();
    var info = leibie + chanpin1 + chanpin2;
    switch (info) {
        case "语文图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSywTslFxg);
            break;
        case "语文图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSywTslFda);
            break;
        case "数学图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSsxTslFxg);
            break;
        case "数学图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSsxTslFda);
            break;
        case "英语图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSyyTslFxg);
            break;
        case "英语图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSyyTslFda);
            break;
        case "政治图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSzzTslFxg);
            break;
        case "政治图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSzzTslFda);
            break;
        case "历史图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSlsTslFxg);
            break;
        case "历史图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSlsTslFda);
            break;
        case "地理图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSdlTslFxg);
            break;
        case "地理图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSdlTslFda);
            break;
        case "物理图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSwlTslFxg);
            break;
        case "物理图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSwlTslFda);
            break;
        case "物理图书类删 教师讲解":
            xueshenggeshishuju(XSGSwlTslSjsjj);
            break;
        case "化学图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGShxTslFxg);
            break;
        case "化学图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGShxTslFda);
            break;
        case "生物图书类教用 分 学用 / 固用":
            xueshenggeshishuju(XSGSswTslFxg);
            break;
        case "生物图书类学用 / 固用 分 答案":
            xueshenggeshishuju(XSGSswTslFda);
            break;
        default:
            xueshenggeshishuju(XSGSnull);
            break;
    }
}

//学生格式数据加载
function xueshenggeshishuju(sjlx) {
    var num = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"];
    $("#xueshenggeshiliebiao").html("");
    for (i = 0; i < 10; i++) {
        if (sjlx[i].tx != "") {
            $("#xueshenggeshiliebiao").append('\
                <div class="xuesheng-zhengzechuli-box">\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '查找&nbsp;&nbsp;</span>\
                    <div id="xueshengcz' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].cz + '</div>\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '提取&nbsp;&nbsp;</span>\
                    <div id="xueshength' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].th + '</div>\
                </div>\
                <div class="xuesheng-zhengzechuli-box">\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '题型&nbsp;&nbsp;</span>\
                    <div id="xueshengxgq' + (i + 1) + '" class="div-box-grep-shezhi-zhanshi">' + sjlx[i].tx + '</div>\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '格式&nbsp;&nbsp;</span>\
                    <div id="xueshengxgh' + (i + 1) + '" class="div-box-grep-shezhi-zhanshi">' + sjlx[i].gs + '</div>\
                </div>\
            ');
        } else {
            $("#xueshenggeshiliebiao").append('\
                <div class="xuesheng-zhengzechuli-box">\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '查找&nbsp;&nbsp;</span>\
                    <div id="xueshengcz' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].cz + '</div>\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '提取&nbsp;&nbsp;</span>\
                    <div id="xueshength' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].th + '</div>\
                </div>\
            ');
        }
    }
}

//答案格式
function daansz() {
    if ($("#daansz").attr("class") == "div-box-top-xianshi-fuxuan") {
        $("#daansz").removeClass("div-box-top-xianshi-fuxuan").addClass("div-box-top-xianshi-fuxuan-xuanze");
        $("#xueshengsz").removeClass("div-box-top-xianshi-fuxuan-xuanze").addClass("div-box-top-xianshi-fuxuan");
        $("#daangeshishezhi").fadeIn("slow");
        $(".div-box-center-in").scrollLeft(3000);
        $("#xueshenggeshishezhi").hide();
    } else if ($("#daansz").attr("class") == "div-box-top-xianshi-fuxuan-xuanze") {
        $("#daansz").removeClass("div-box-top-xianshi-fuxuan-xuanze").addClass("div-box-top-xianshi-fuxuan");
        $(".div-box-center-in").scrollLeft(0);
    }
}

//答案格式科目判定
function daangeshikemupanding() {
    var leibie = $("#leibie").val();
    var chanpin1 = $("#chanpin1").val();
    var chanpin2 = $("#chanpin2").val();
    var info = leibie + chanpin1 + chanpin2;
    switch (info) {
        case "语文图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSywTslFxg);
            break;
        case "语文图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSywTslFda);
            break;
        case "数学图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSsxTslFxg);
            break;
        case "数学图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSsxTslFda);
            break;
        case "英语图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSyyTslFxg);
            break;
        case "英语图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSyyTslFda);
            break;
        case "政治图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSzzTslFxg);
            break;
        case "政治图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSzzTslFda);
            break;
        case "历史图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSlsTslFxg);
            break;
        case "历史图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSlsTslFda);
            break;
        case "地理图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSdlTslFxg);
            break;
        case "地理图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSdlTslFda);
            break;
        case "物理图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSwlTslFxg);
            break;
        case "物理图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSwlTslFda);
            break;
        case "化学图书类教用 分 学用 / 固用":
            daangeshishuju(DAGShxTslFxg);
            break;
        case "化学图书类学用 / 固用 分 答案":
            daangeshishuju(DAGShxTslFda);
            break;
        case "生物图书类教用 分 学用 / 固用":
            daangeshishuju(DAGSswTslFxg);
            break;
        case "生物图书类学用 / 固用 分 答案":
            daangeshishuju(DAGSswTslFda);
            break;
        default:
            daangeshishuju(DAGSnull);
            break;
    }
}

//答案格式数据加载
function daangeshishuju(sjlx) {
    var num = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10"];
    $("#daangeshiliebiao").html("");
    for (i = 0; i < 10; i++) {
        if (sjlx[i].tx != "") {
            $("#daangeshiliebiao").append('\
                <div class="daan-zhengzechuli-box">\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '查找&nbsp;&nbsp;</span>\
                    <div id="daancz' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].cz + '</div>\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '提取&nbsp;&nbsp;</span>\
                    <div id="daanth' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].th + '</div>\
                </div>\
                <div class="daan-zhengzechuli-box">\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '题型&nbsp;&nbsp;</span>\
                    <div id="daanxgq' + (i + 1) + '" class="div-box-grep-shezhi-zhanshi">' + sjlx[i].tx + '</div>\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '格式&nbsp;&nbsp;</span>\
                    <div id="daanxgh' + (i + 1) + '" class="div-box-grep-shezhi-zhanshi">' + sjlx[i].gs + '</div>\
                </div>\
            ');
        } else {
            $("#daangeshiliebiao").append('\
                <div class="daan-zhengzechuli-box">\
                <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '查找&nbsp;&nbsp;</span>\
                    <div id="daancz' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].cz + '</div>\
                    <span class="div-box-top-shezhi-tiaomu-div-sp">' + num[i] + '提取&nbsp;&nbsp;</span>\
                    <div id="daanth' + (i + 1) + '" class="div-box-grep-shezhi-shuru" contenteditable="true">' + sjlx[i].th + '</div>\
                </div>\
            ');
        }
    }
}

//拆分提交
function chaifen() {
    if ($("#chaifenanniu").attr("class") == "div-box-top-chaifen-anniu") {
        jiaoshigaoliangN();
        var leibie = $("#leibie").val();
        var chanpin1 = $("#chanpin1").val();
        var chanpin2 = $("#chanpin2").val();
        var tiqu1 = $("#tiqu1").val();
        var tiqu2 = $("#tiqu2").val();
        var jiaoshiC = $("#jiaoshiC").html();

        jiaoshiC = jiaoshiC.replace(/\[/g, "〖");
        jiaoshiC = jiaoshiC.replace(/\]/g, "〗");

        var xueshengCA = jiaoshiC.match(new RegExp(tiqu1, 'g'));
        var daanCA = jiaoshiC.match(new RegExp(tiqu2, 'g'));
        if (xueshengCA == null || daanCA == null) {
            if (chanpin2.indexOf("分 答案") >= 0) {
                $("#xueshengbiaoti").html("学生/固学案部分");
                $("#daanbiaoti").html("答案部分");
            } else if (chanpin2.indexOf("分 学用") >= 0) {
                $("#xueshengbiaoti").html("学用部分");
                $("#daanbiaoti").html("固用部分");
            } else {
                $("#xueshengbiaoti").html("学用部分");
                $("#daanbiaoti").html("答案部分");
            }
            $("#xueshengbiaoti").css("color", colorMoshi4);

            $("#daanbiaoti").css("color", colorMoshi4);
            $("#xueshengC").html("");
            $("#daanC").html("");
            swal("拆分异常", "“提取的学生” 或 “提取的答案” 找不到内容", "error");
            // } else if (xueshengCA != null && daanCA != null && xueshengCA.length == daanCA.length) {
        } else {

            var xueshengC = jiaoshiC;

            // var oneArray = ["图书类教用 分 学用 / 固用", "图书类学用 / 固用 分 答案"];

            var oneArray = ["图书类教用 分 学用 / 固用"];

            // var twoArray = ["图书类学用 / 固用 分 答案"];

            // console.log(oneArray.indexOf(leibie + chanpin1 + chanpin2));

            if (leibie == "英语" && chanpin2 == "教用 分 学用 / 固用") {

                // var xueshengC = xueshengC.replace(new RegExp(tiqu1, "g"), "");
                // xueshengN = xueshengChuli(xueshengC);
                var xueshengN = "";

                xueshengC = xueshengC.replace(new RegExp("〖BP[（(]〗[\\s\\S]+?〖BP[)）]〗", "g"), "");

                var xueshengCArray = xueshengC.match(new RegExp(tiqu1, "g"));

                for (let i = 0; i < xueshengCArray.length; i++) {
                    xueshengN += xueshengChuli(xueshengCArray[i]) + "\n\n";
                }

            } else {

                if (leibie == "语文" && chanpin2 == "学用 / 固用 分 答案") {
                    var xueshengC = xueshengC.replace(new RegExp("[〓]*?\\n〖QX[（(]Z0〗.*?〖=DA[（(]〗与你交流〖=〗[\\s\\S]+?〖QX[)）]〗", "g"), "\n〖HY8mm〗\n〖ZZ1Z〗〖JY〗〓\n〖ZZ1Z〗〖JY〗〓\n〖ZZ1Z〗〖JY〗〓\n〖HY〗\n");
                }

                xueshengC = xueshengC.replace(new RegExp(tiqu1, "g"), "");
                xueshengN = xueshengChuli(xueshengC);

            }

            // if (oneArray.indexOf(chanpin1 + chanpin2) >= 0)

            // else {

            //     // console.log(leibie + chanpin1 + chanpin2);

            //     // console.log(twoArray.indexOf(leibie + chanpin1 + chanpin2));

            //     var xueshengN = "";

            //     xueshengC = xueshengC.replace(new RegExp("〖BP[（(]〗[\\s\\S]+?〖BP[)）]〗", "g"), "");

            //     var xueshengCArray = xueshengC.match(new RegExp(tiqu1, "g"));

            //     for (let i = 0; i < xueshengCArray.length; i++) {
            //         xueshengN += xueshengChuli(xueshengCArray[i]) + "\n\n";
            //     }

            // }

            function xueshengChuli(xueshengC) {
                //学生格式获取
                var xueshengcz1 = $("#xueshengcz1").html();
                var xueshength1 = $("#xueshength1").html();
                xueshengcz1 = HTMLDecode(xueshengcz1);
                xueshength1 = xueshength1.replace(/\\n/g, "\n");
                var xueshengcz2 = $("#xueshengcz2").html();
                var xueshength2 = $("#xueshength2").html();
                xueshengcz2 = HTMLDecode(xueshengcz2);
                xueshength2 = xueshength2.replace(/\\n/g, "\n");
                var xueshengcz3 = $("#xueshengcz3").html();
                var xueshength3 = $("#xueshength3").html();
                xueshengcz3 = HTMLDecode(xueshengcz3);
                xueshength3 = xueshength3.replace(/\\n/g, "\n");
                var xueshengcz4 = $("#xueshengcz4").html();
                var xueshength4 = $("#xueshength4").html();
                xueshengcz4 = HTMLDecode(xueshengcz4);
                xueshength4 = xueshength4.replace(/\\n/g, "\n");
                var xueshengcz5 = $("#xueshengcz5").html();
                var xueshength5 = $("#xueshength5").html();
                xueshengcz5 = HTMLDecode(xueshengcz5);
                xueshength5 = xueshength5.replace(/\\n/g, "\n");
                var xueshengcz6 = $("#xueshengcz6").html();
                var xueshength6 = $("#xueshength6").html();
                xueshengcz6 = HTMLDecode(xueshengcz6);
                xueshength6 = xueshength6.replace(/\\n/g, "\n");
                var xueshengcz7 = $("#xueshengcz7").html();
                var xueshength7 = $("#xueshength7").html();
                xueshengcz7 = HTMLDecode(xueshengcz7);
                xueshength7 = xueshength7.replace(/\\n/g, "\n");
                var xueshengcz8 = $("#xueshengcz8").html();
                var xueshength8 = $("#xueshength8").html();
                xueshengcz8 = HTMLDecode(xueshengcz8);
                xueshength8 = xueshength8.replace(/\\n/g, "\n");
                var xueshengcz9 = $("#xueshengcz9").html();
                var xueshength9 = $("#xueshength9").html();
                xueshengcz9 = HTMLDecode(xueshengcz9);
                xueshength9 = xueshength9.replace(/\\n/g, "\n");
                var xueshengcz10 = $("#xueshengcz10").html();
                var xueshength10 = $("#xueshength10").html();
                xueshengcz10 = HTMLDecode(xueshengcz10);
                xueshength10 = xueshength10.replace(/\\n/g, "\n");

                //学生格式处理
                if (xueshengcz1 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz1, 'g'), xueshength1);
                }
                if (xueshengcz2 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz2, 'g'), xueshength2);
                }
                if (xueshengcz3 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz3, 'g'), xueshength3);
                }
                if (xueshengcz4 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz4, 'g'), xueshength4);
                }
                if (xueshengcz5 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz5, 'g'), xueshength5);
                }
                if (xueshengcz6 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz6, 'g'), xueshength6);
                }
                if (xueshengcz7 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz7, 'g'), xueshength7);
                }
                if (xueshengcz8 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz8, 'g'), xueshength8);
                }
                if (xueshengcz9 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz9, 'g'), xueshength9);
                }
                if (xueshengcz10 != "") {
                    xueshengC = xueshengC.replace(new RegExp(xueshengcz10, 'g'), xueshength10);
                }
                return xueshengC;
            }

            $("#xueshengC").html(xueshengN);
            $("#xueshengzifu").html(xueshengC.length);
            if (chanpin2.indexOf("分 答案") >= 0) {
                $("#xueshengbiaoti").html("学生/固学案部分");
                $("#daanbiaoti").html("答案部分");
            } else if (chanpin2.indexOf("分 学用") >= 0) {
                $("#xueshengbiaoti").html("学用部分");
                $("#daanbiaoti").html("固用部分");
            } else {
                $("#xueshengbiaoti").html("学用部分");
                $("#daanbiaoti").html("答案部分");
            }
            $("#xueshengbiaoti").css("color", colorMoshi1);

            var daanC = jiaoshiC;
            var daanN = "";

            daanC = daanC.replace(new RegExp("〖BP[（(]〗[\\s\\S]*?〖BP[)）]〗", "g"), "");

            var daanCArray = daanC.match(new RegExp(tiqu2, "g"), "");

            for (let i = 0; i < daanCArray.length; i++) {
                daanN += daanChuli(daanCArray[i]) + "\n\n";
            }

            function daanChuli(daanC) {
                //答案格式获取
                var daancz1 = $("#daancz1").html();
                var daanth1 = $("#daanth1").html();
                daancz1 = HTMLDecode(daancz1);
                daanth1 = daanth1.replace(/\\n/g, "\n");
                var daancz2 = $("#daancz2").html();
                var daanth2 = $("#daanth2").html();
                daancz2 = HTMLDecode(daancz2);
                daanth2 = daanth2.replace(/\\n/g, "\n");
                var daancz3 = $("#daancz3").html();
                var daanth3 = $("#daanth3").html();
                daancz3 = HTMLDecode(daancz3);
                daanth3 = daanth3.replace(/\\n/g, "\n");
                var daancz4 = $("#daancz4").html();
                var daanth4 = $("#daanth4").html();
                daancz4 = HTMLDecode(daancz4);
                daanth4 = daanth4.replace(/\\n/g, "\n");
                var daancz5 = $("#daancz5").html();
                var daanth5 = $("#daanth5").html();
                daancz5 = HTMLDecode(daancz5);
                daanth5 = daanth5.replace(/\\n/g, "\n");
                var daancz6 = $("#daancz6").html();
                var daanth6 = $("#daanth6").html();
                daancz6 = HTMLDecode(daancz6);
                daanth6 = daanth6.replace(/\\n/g, "\n");
                var daancz7 = $("#daancz7").html();
                var daanth7 = $("#daanth7").html();
                daancz7 = HTMLDecode(daancz7);
                daanth7 = daanth7.replace(/\\n/g, "\n");
                var daancz8 = $("#daancz8").html();
                var daanth8 = $("#daanth8").html();
                daancz8 = HTMLDecode(daancz8);
                daanth8 = daanth8.replace(/\\n/g, "\n");
                var daancz9 = $("#daancz9").html();
                var daanth9 = $("#daanth9").html();
                daancz9 = HTMLDecode(daancz9);
                daanth9 = daanth9.replace(/\\n/g, "\n");
                var daancz10 = $("#daancz10").html();
                var daanth10 = $("#daanth10").html();
                daancz10 = HTMLDecode(daancz10);
                daanth10 = daanth10.replace(/\\n/g, "\n");

                //答案格式处理
                if (daancz1 != "") {
                    daanC = daanC.replace(new RegExp(daancz1, 'g'), daanth1);
                }
                if (daancz2 != "") {
                    daanC = daanC.replace(new RegExp(daancz2, 'g'), daanth2);
                }
                if (daancz3 != "") {
                    daanC = daanC.replace(new RegExp(daancz3, 'g'), daanth3);
                }
                if (daancz4 != "") {
                    daanC = daanC.replace(new RegExp(daancz4, 'g'), daanth4);
                }
                if (daancz5 != "") {
                    daanC = daanC.replace(new RegExp(daancz5, 'g'), daanth5);
                }
                if (daancz6 != "") {
                    daanC = daanC.replace(new RegExp(daancz6, 'g'), daanth6);
                }
                if (daancz7 != "") {
                    daanC = daanC.replace(new RegExp(daancz7, 'g'), daanth7);
                }
                if (daancz8 != "") {
                    daanC = daanC.replace(new RegExp(daancz8, 'g'), daanth8);
                }
                if (daancz9 != "") {
                    daanC = daanC.replace(new RegExp(daancz9, 'g'), daanth9);
                }
                if (daancz10 != "") {
                    daanC = daanC.replace(new RegExp(daancz10, 'g'), daanth10);
                }
                return daanC;
            }

            daanN = daanN.replace(new RegExp('〖JZ〗〖XC.+?〗\\n.+?[（(]见《固学案》.+?[）)]〖HT〗', "g"), "");

            daanN = daanN.replace(new RegExp("(\\d+[.．]\\n\\n)(\\d+[.．]\\n\\n)+", 'g'), "");
            daanN = daanN.replace(new RegExp("([（()]\\d+[)）]\\n\\n)([（()]\\d+[)）]\\n\\n)+", 'g'), "");

            if (leibie + chanpin1 + chanpin2 == "数学图书类学用 / 固用 分 答案") {
                daanN = daanN.replace(new RegExp("〓\n\n(?=.+〓)", 'g'), "〓");
                daanN = daanN.replace(new RegExp("〓\n\n(?!.+〓)", 'g'), "\n\n");
            }

            if (leibie + chanpin1 + chanpin2 == "政治图书类学用 / 固用 分 答案") {
                daanN = daanN.replace(new RegExp("(?<=〖ZK[（(]〗)\n\n", 'g'), "");
            }

            $("#daanC").html(daanN);
            $("#daanzifu").html(daanC.length);
            $("#daanbiaoti").css("color", colorMoshi1);

            swal(chanpin1 + "\n" + leibie + " 拆分成功", "“拆分内容” 请自行粘贴使用", "success");
            // } else {
            //     $("#xueshengbiaoti").html("学用部分");
            //     $("#xueshengbiaoti").css("color", colorMoshi4);
            //     $("#daanbiaoti").html("答案部分");
            //     $("#daanbiaoti").css("color", colorMoshi4);
            //     $("#xueshengC").html("");
            //     $("#daanC").html("");
            //     swal("拆分异常", "“替换的内文” 与 “提取的答案” 数量不匹配", "error");
        }
    }
}

//拆分判定
function chaifenPanding() {
    var jiaoshiC = $("#jiaoshiC").html();
    var tiqu2 = $("#tiqu2").val();
    $("#xueshengzifu").html(0);
    $("#daabzifu").html(0);
    if (($("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" || $("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi") && jiaoshiC != "" && tiqu2 != "") {
        $("#chaifenanniu").removeClass("div-box-top-chaifen-anniu-jinzhi").addClass("div-box-top-chaifen-anniu");
    } else {
        $("#chaifenanniu").removeClass("div-box-top-chaifen-anniu").addClass("div-box-top-chaifen-anniu-jinzhi");
    }
}

//教用输入字符统计
function jiaoshiZifuTongji() {
    var jiaoshiC = $("#jiaoshiC").html();
    $("#jiaoshizifu").html(jiaoshiC.length);
}

//教用输入
function jiaoshishuru() {
    var chanpin2 = $("#chanpin2").val();
    $("#jiaoshiwenjianming-box").html("");
    var jiaoshiC = $("#jiaoshiC").html();
    var tiqu2 = $("#tiqu2").val();
    jiaoshiZifuTongji();
    if (jiaoshiC != "") {
        $("#jiaoshibiaoti").css("color", colorMoshi1);
        if ($("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu1 != "") {
            $("#tiqu1queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
        }
        if ($("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu2 != "") {
            $("#tiqu2queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
        }
    } else {
        $("#jiaoshibiaoti").css("color", colorMoshi4);
        tiqu1quedingY();
        tiqu2quedingY();
    }
    if (chanpin2.indexOf("分 学用") >= 0) {
        $("#jiaoshibiaoti").html("教用部分");
    } else if (chanpin2.indexOf("分 答案") >= 0) {
        $("#jiaoshibiaoti").html("学用/固用部分");
    } else {
        $("#jiaoshibiaoti").html("教用部分");
    }
    chaifenPanding();
    chaifenfuwei();
}

//教用高亮
function jiaoshigaoliang() {
    tiqu1 = $("#tiqu1").val();
    tiqu2 = $("#tiqu2").val();
    jiaoshiC = $("#jiaoshiC").html();
    if (tiqu1 != "" && tiqu2 != "" && jiaoshiC != "" && $("#jiaoshigaoliang").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng" && $("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding" && $("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding") {
    } else if (tiqu1 != "" && (tiqu2 != "" || jiaoshiC != "") && $("#jiaoshigaoliang").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng" && ($("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" || $("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi")) {
        jiaoshigaoliangY();
    } else {
        // console.log(1);
        jiaoshigaoliangN();
    }
    chaifenPanding();
}

//教用高亮开启
function jiaoshigaoliangY() {
    $("#jiaoshigaoliang").removeClass("div-box-center-mokuai-bufen-shuru-gongneng").addClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze");
    var tiqu1 = $("#tiqu1").val();
    var tiqu2 = $("#tiqu2").val();
    var jiaoshiC = $("#jiaoshiC").html();
    thbj = "提取标记"
    if (jiaoshiC != "") {
        if (tiqu1 != "" && $("#tiqu1queding").attr("class") == "div-box-top-xianshi-queding-jinzhi") {
            var jiaoshiCount = jiaoshiC.match(new RegExp(tiqu1, 'g'));
            tiqu1 = "(" + tiqu1 + ")";
            jiaoshiC = jiaoshiC.replace(new RegExp(tiqu1, 'g'), ("<span style='transition: all 0.1s; background:" + colorMoshi5 + ";color:" + colorMoshi3 + "'>" + thbj + "$1</span>"));
        } else if (tiqu2 != "" && $("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi") {
            var jiaoshiCount = jiaoshiC.match(new RegExp(tiqu2, 'g'));
            tiqu2 = "(" + tiqu2 + ")";
            jiaoshiC = jiaoshiC.replace(new RegExp(tiqu2, 'g'), ("<span style='transition: all 0.1s; background:" + colorMoshi5 + ";color:" + colorMoshi3 + "'>" + thbj + "$1</span>"));
        } else {
            var jiaoshiCount = null;
        }
    }
    var jiaoshiXuhao = "(<span.+?>)" + thbj + "([\\s\\S]+?)(</span>)";
    if (jiaoshiCount != null) {
        for (i = 0; i < jiaoshiCount.length; i++) {
            jiaoshiC = jiaoshiC.replace(new RegExp(jiaoshiXuhao), ("$1提取" + (i + 1) + "→ $2$3"));
        }
    }
    jiaoshiC = jiaoshiC.replace(/\n/g, "<br>")
    $("#jiaoshiC").html(jiaoshiC);
    $("#jiaoshiC").css("-webkit-user-modify", "read-only");
    $("#jiaoshiC").css("user-select", "none");
}

//教用高亮关闭
function jiaoshigaoliangN() {
    $("#jiaoshigaoliang").removeClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze").addClass("div-box-center-mokuai-bufen-shuru-gongneng");
    var jiaoshiC = $("#jiaoshiC").html();
    jiaoshiC = jiaoshiC.replace(/<span style.+?提取\d+→ /g, "");
    jiaoshiC = jiaoshiC.replace(/<\/span>/g, "");
    jiaoshiC = jiaoshiC.replace(/<br>/g, "\n")
    $("#jiaoshiC").html(jiaoshiC);
    $("#jiaoshiC").css("-webkit-user-modify", "read-write-plaintext-only");
    $("#jiaoshiC").css("user-select", "auto");
}

//教用书版
function jiaoshishuban() {
    var file = $("#jiaoshiwenjian").prop('files'); //获取到文件列表
    if (file.length > 0) { //判断读取文件是否存在
        var reader = new FileReader(); //新建一个FileReader
        reader.readAsText(file[0], "gb2312"); //读取文件 
        reader.onload = function (evt) { //读取完文件之后会回来这里
            var filetring = evt.target.result; // 读取文件内容
            filetring = HTMLEncode(filetring);
            $("#jiaoshiC").html(filetring); //赋值文件到教用框
            var jiaoshiC = $("#jiaoshiC").html();
            jiaoshiZifuTongji();
            if (jiaoshiC != "") {
                $("#jiaoshibiaoti").css("color", colorMoshi1);
            } else {
                $("#jiaoshibiaoti").css("color", colorMoshi4);
            };
            $("#jiaoshiwenjianming-box").html(""); //清空文件名
            $("#jiaoshiwenjianming-box").append("<span id='jiaoshiwenjianming'>" + file[0].name + "</span>"); //赋予新的读取文件的文件名到教用标题
            $("#jiaoshiwenjian").val(""); //清空文件对象
        }
        $("#jiaoshibiaoti").css("color", colorMoshi1);
        if ($("#tiqu2queding").attr("class") == "div-box-top-xianshi-queding-jinzhi" && jiaoshiC != "" && tiqu2 != "") {
            $("#tiqu2queding").removeClass("div-box-top-xianshi-queding-jinzhi").addClass("div-box-top-xianshi-queding");
        }
        $("#jiaoshibiaoti").html("教用部分");
        $("#xueshengC").html("");
        $("#xueshengzifu").html(0);
        $("#xueshengbiaoti").html("学用部分");
        $("#xueshengbiaoti").css("color", colorMoshi4);
        $("#daanC").html("");
        $("#daanzifu").html(0);
        $("#daanbiaoti").html("答案部分");
        $("#daanbiaoti").css("color", colorMoshi4);
    }
}

//教用放大
function jiaoshifangda() {
    if ($("#jiaoshifangda").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng") {
        jiaoshifangdaY();
    } else if ($("#jiaoshifangda").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng-xuanze") {
        jiaoshifangdaN();
    }
}

//教用放大开启
function jiaoshifangdaY() {
    $("#jiaoshifangda").removeClass("div-box-center-mokuai-bufen-shuru-gongneng").addClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze");
    $("#xueshengmokuai").hide();
    $("#daanmokuai").hide();
    $("#jiaoshifangda").html("缩小");
    $(".div-box-center-mokuai-bufen-shuru").css("width", "1224px");
}

//教用放大关闭
function jiaoshifangdaN() {
    $("#jiaoshifangda").removeClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze").addClass("div-box-center-mokuai-bufen-shuru-gongneng");
    $("#xueshengmokuai").show();
    $("#daanmokuai").show();
    $("#jiaoshifangda").html("放大");
    $(".div-box-center-mokuai-bufen-shuru").css("width", "380px");
}

//学生放大
function xueshengfangda() {
    if ($("#xueshengfangda").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng") {
        xueshengfangdaY();
    } else if ($("#xueshengfangda").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng-xuanze") {
        xueshengfangdaN();
    }
}

//学生放大开启
function xueshengfangdaY() {
    $("#xueshengfangda").removeClass("div-box-center-mokuai-bufen-shuru-gongneng").addClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze");
    $("#jiaoshimokuai").hide();
    $("#daanmokuai").hide();
    $("#xueshengfangda").html("缩小");
    $(".div-box-center-mokuai-bufen-shuru").css("width", "1224px");
}

//学生放大关闭
function xueshengfangdaN() {
    $("#xueshengfangda").removeClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze").addClass("div-box-center-mokuai-bufen-shuru-gongneng");
    $("#jiaoshimokuai").show();
    $("#daanmokuai").show();
    $("#xueshengfangda").html("放大");
    $(".div-box-center-mokuai-bufen-shuru").css("width", "380px");
}

//答案放大
function daanfangda() {
    if ($("#daanfangda").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng") {
        daanfangdaY();
    } else if ($("#daanfangda").attr("class") == "div-box-center-mokuai-bufen-shuru-gongneng-xuanze") {
        daanfangdaN();
    }
}

//答案放大开启
function daanfangdaY() {
    $("#daanfangda").removeClass("div-box-center-mokuai-bufen-shuru-gongneng").addClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze");
    $("#jiaoshimokuai").hide();
    $("#xueshengmokuai").hide();
    $("#daanfangda").html("缩小");
    $(".div-box-center-mokuai-bufen-shuru").css("width", "1224px");
}

//答案放大关闭
function daanfangdaN() {
    $("#daanfangda").removeClass("div-box-center-mokuai-bufen-shuru-gongneng-xuanze").addClass("div-box-center-mokuai-bufen-shuru-gongneng");
    $("#jiaoshimokuai").show();
    $("#xueshengmokuai").show();
    $("#daanfangda").html("放大");
    $(".div-box-center-mokuai-bufen-shuru").css("width", "380px");
}

//拆分复位
function chaifenfuwei() {
    var chanpin2 = $("#chanpin2").val();
    $("#xueshengC").html("");
    $("#xueshengzifu").html(0);
    if (chanpin2.indexOf("分 学用") >= 0) {
        $("#jiaoshibiaoti").html("教用部分");
        $("#xueshengbiaoti").html("学用部分");
        $("#daanbiaoti").html("固用部分");
    } else if (chanpin2.indexOf("分 答案") >= 0) {
        $("#jiaoshibiaoti").html("学用/固用部分");
        $("#xueshengbiaoti").html("学生/固学案部分");
        $("#daanbiaoti").html("答案部分");
    } else {
        $("#jiaoshibiaoti").html("教用部分");
        $("#xueshengbiaoti").html("学用部分");
        $("#daanbiaoti").html("答案部分");
    }
    $("#xueshengbiaoti").css("color", colorMoshi4);
    $("#daanC").html("");
    $("#daanzifu").html(0);
    $("#daanbiaoti").css("color", colorMoshi4);
}

//HTML转义字符
function HTMLEncode(html) {
    var temp = document.createElement("div");
    (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
    var output = temp.innerHTML;
    temp = null;
    return output;
}

//HTML反转义字符
function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
}